/*
Written by Alex Chachanashvili

$Id: ACryptoConstants.hpp 73 2008-05-29 23:22:29Z achacha $
*/
#ifndef INCLUDED_ACryptoConstants_HPP__
#define INCLUDED_ACryptoConstants_HPP__

// Blowfish
#define BF_CBC			"BF-CBC"
#define BF_CFB64		"BF-CFB"
#define BF_ECB			"BF-ECB"
#define BF_OFB64		"BF-OFB"

// CAST
#define CAST5_CBC		"CAST5-CBC"
#define CAST5_CFB64		"CAST5-CFB"
#define CAST5_ECB		"CAST5-ECB"
#define CAST5_OFB64		"CAST5-OFB"

// DES
#define DES_CBC			"DES-CBC"
#define DES_CFB64		"DES-CFB"
#define DES_ECB			"DES-ECB"
#define DES_EDE			"DES-EDE"
#define DES_EDE3		"DES-EDE3"
#define DES_EDE3_CBC		"DES-EDE3-CBC"
#define DES_EDE3_CFB64		"DES-EDE3-CFB"
#define DES_EDE3_OFB64		"DES-EDE3-OFB"
#define DES_EDE_CBC		"DES-EDE-CBC"
#define DES_EDE_CFB64		"DES-EDE-CFB"
#define DES_EDE_OFB64		"DES-EDE-OFB"
#define DES_OFB64		"DES-OFB"
#define DESX_CBC		"DESX-CBC"

// DSA
#define DSAWITHSHA		"DSA-SHA"
#define DSAWITHSHA1		"DSA-SHA1"
#define DSAWITHSHA1_2		"DSA-SHA1-OLD"
#define DSA_2			"DSA-OLD"

// IDEA
#define IDEA_CBC		"IDEA-CBC"
#define IDEA_CFB64		"IDEA-CFB"
#define IDEA_ECB		"IDEA-ECB"
#define IDEA_OFB64		"IDEA-OFB"

// MD2
#define MD2			"MD2"
#define MD2WITHRSAENCRYPTION	"RSA-MD2"

// MD5
#define MD5			"MD5"
#define MD5WITHRSA		"RSA-NP-MD5"
#define MD5WITHRSAENCRYPTION	"RSA-MD5"
#define MD5_SHA1		"MD5-SHA1"
#define MDC2			"MDC2"
#define MDC2WITHRSA		"RSA-MDC2"

// RC2
#define RC2_40_CBC		"RC2-40-CBC"
#define RC2_CBC			"RC2-CBC"
#define RC2_CFB64		"RC2-CFB"
#define RC2_ECB			"RC2-ECB"
#define RC2_OFB64		"RC2-OFB"

// RC4
#define RC4			"RC4"
#define RC4_40			"RC4-40"

// RC5
#define RC5_CBC			"RC5-CBC"
#define RC5_CFB64		"RC5-CFB"
#define RC5_ECB			"RC5-ECB"
#define RC5_OFB64		"RC5-OFB"

// RIPEMD160
#define RIPEMD160		"RIPEMD160"
#define RIPEMD160WITHRSA	"RSA-RIPEMD160"

// SHA
#define SHA			"SHA"
#define SHA1			"SHA1"
#define SHA1WITHRSA		"RSA-SHA1-2"
#define SHA1WITHRSAENCRYPTION	"RSA-SHA1"
#define SHAWITHRSAENCRYPTION	"RSA-SHA"


// Cipher list by name
static char *ACRYPTO_cipher_list[] = {
  BF_CBC,
  BF_CFB64,
  BF_ECB,
  BF_OFB64,
  CAST5_CBC,
  CAST5_CFB64,
  CAST5_ECB,
  CAST5_OFB64,
  DES_CBC,
  DES_CFB64,
  DES_ECB,
  DES_EDE,
  DES_EDE3,
  DES_EDE3_CBC,
  DES_EDE3_CFB64,
  DES_EDE3_OFB64,
  DES_EDE_CBC,
  DES_EDE_CFB64,
  DES_EDE_OFB64,
  DES_OFB64,
  DESX_CBC,
  IDEA_CBC,
  IDEA_CFB64,
  IDEA_ECB,
  IDEA_OFB64,
  RC2_40_CBC,
  RC2_CBC,
  RC2_CFB64,
  RC2_ECB,
  RC2_OFB64,
  RC4,
  RC4,
  RC4_40,
  RC5_CBC,
  RC5_CFB64,
  RC5_ECB,
  RC5_OFB64, 
  NULL
};

// Error codes
#define ACRYPTO_OK          0

#define ACRYPTO_ERR_BASE        -100
#define ACRYPTO_ERR_ALLOCATION_FAILURE                ACRYPTO_ERR_BASE - 1
#define ACRYPTO_ERR_SRC_PTR_NULL                      ACRYPTO_ERR_BASE - 2
#define ACRYPTO_ERR_DEST_PTR_NULL                     ACRYPTO_ERR_BASE - 3
#define ACRYPTO_ERR_INVALID_SRC_SIZE                  ACRYPTO_ERR_BASE - 4
#define ACRYPTO_ERR_INVALID_DEST_SIZE                 ACRYPTO_ERR_BASE - 5
#define ACRYPTO_ERR_INVALID_BASE_KEY                  ACRYPTO_ERR_BASE - 6
#define ACRYPTO_ERR_INVALID_BASE_IV                   ACRYPTO_ERR_BASE - 7
#define ACRYPTO_ERR_INVALID_BASE_DIGEST               ACRYPTO_ERR_BASE - 8
#define ACRYPTO_ERR_INVALID_BASE_CIPHER               ACRYPTO_ERR_BASE - 9
#define ACRYPTO_ERR_INVALID_CIPHER_MODE               ACRYPTO_ERR_BASE - 10
#define ACRYPTO_ERR_INVALID_CIPHER_NAME               ACRYPTO_ERR_BASE - 11
#define ACRYPTO_ERR_INVALID_EVP_CIPHER                ACRYPTO_ERR_BASE - 12
#define ACRYPTO_ERR_INVALID_EVP_DIGEST                ACRYPTO_ERR_BASE - 13
#define ACRYPTO_ERR_INVALID_FILE_DESCRIPTOR           ACRYPTO_ERR_BASE - 14
#define ACRYPTO_ERR_INVALID_FILE_NAME                 ACRYPTO_ERR_BASE - 15
#define ACRYPTO_ERR_INVALID_FILE_MODE                 ACRYPTO_ERR_BASE - 16
#define ACRYPTO_ERR_INVALID_FILE_POINTER              ACRYPTO_ERR_BASE - 17
#define ACRYPTO_ERR_INVALID_BIO_PTR                   ACRYPTO_ERR_BASE - 18

// Asymmetric cipher set
#define ACRYPTO_ERR_ASYM_INVALID_PADDING_MODE         ACRYPTO_ERR_BASE - 19
#define ACRYPTO_ERR_ASYM_INVALID_MODE                 ACRYPTO_ERR_BASE - 20
#define ACRYPTO_ERR_ASYM_INVALID_CONTEXT              ACRYPTO_ERR_BASE - 21
#define ACRYPTO_ERR_ASYM_INVALID_FILE_MODE            ACRYPTO_ERR_BASE - 22
#define ACRYPTO_ERR_ASYM_INVALID_MODULUS_SIZE         ACRYPTO_ERR_BASE - 23
#define ACRYPTO_ERR_ASYM_INVALID_RSA_EXP_MODE         ACRYPTO_ERR_BASE - 24
#define ACRYPTO_ERR_ASYM_INVALID_RSA_CONTEXT          ACRYPTO_ERR_BASE - 25
#define ACRYPTO_ERR_ASYM_INVALID_DSA_CONTEXT          ACRYPTO_ERR_BASE - 26
#define ACRYPTO_ERR_ASYM_INVALID_DH_EXP_MODE          ACRYPTO_ERR_BASE - 27
#define ACRYPTO_ERR_ASYM_INVALID_DH_CONTEXT           ACRYPTO_ERR_BASE - 28
#define ACRYPTO_ERR_ASYM_INVALID_DATA_LENGTH          ACRYPTO_ERR_BASE - 29
#define ACRYPTO_ERR_ASYM_INVALID_RSA_PUBLIC_ENCRYPT   ACRYPTO_ERR_BASE - 30
#define ACRYPTO_ERR_ASYM_INVALID_RSA_PRIVATE_ENCRYPT  ACRYPTO_ERR_BASE - 31
#define ACRYPTO_ERR_ASYM_INVALID_RSA_PUBLIC_DECRYPT   ACRYPTO_ERR_BASE - 32
#define ACRYPTO_ERR_ASYM_INVALID_RSA_PRIVATE_DECRYPT  ACRYPTO_ERR_BASE - 33

// Certificates
#define ACRYPTO_ERR_CERT_INVALID_CERT_FORMAT          ACRYPTO_ERR_BASE - 34
#define ACRYPTO_ERR_CERT_INVALID_CERT_FILE            ACRYPTO_ERR_BASE - 35
#define ACRYPTO_ERR_CERT_INVALID_CERT_REQ             ACRYPTO_ERR_BASE - 36
#define ACRYPTO_ERR_CERT_INVALID_CERT_HEADER          ACRYPTO_ERR_BASE - 37
#define ACRYPTO_ERR_CERT_INVALID_CERT                 ACRYPTO_ERR_BASE - 38
#define ACRYPTO_ERR_CERT_INVALID_PUBKEY               ACRYPTO_ERR_BASE - 39
#define ACRYPTO_ERR_CERT_INVALID_PUBKEY_VERIFY        ACRYPTO_ERR_BASE - 40
#define ACRYPTO_ERR_CERT_INVALID_PRIVKEY              ACRYPTO_ERR_BASE - 41
#define ACRYPTO_ERR_CERT_INVALID_PRIVKEY_FILE         ACRYPTO_ERR_BASE - 42
#define ACRYPTO_ERR_CERT_INVALID_KEY_FORMAT           ACRYPTO_ERR_BASE - 43
#define ACRYPTO_ERR_CERT_INVALID_DAYS                 ACRYPTO_ERR_BASE - 44
#define ACRYPTO_ERR_CERT_INVALID_ISSUER_NAME          ACRYPTO_ERR_BASE - 45
#define ACRYPTO_ERR_CERT_INVALID_GMTIME               ACRYPTO_ERR_BASE - 46
#define ACRYPTO_ERR_CERT_SIGN_FAILED                  ACRYPTO_ERR_BASE - 47

// Secret sharing algorithm
#define ACRYPTO_ERR_SSA_TOO_MANY_SHARES               ACRYPTO_ERR_BASE - 48
#define ACRYPTO_ERR_SSA_TOO_FEW_SHARES                ACRYPTO_ERR_BASE - 49
#define ACRYPTO_ERR_SSA_TOTAL_REQUIRED_MISMATCH       ACRYPTO_ERR_BASE - 50
#define ACRYPTO_ERR_SSA_MASTER_BUFFER_MISMATCH        ACRYPTO_ERR_BASE - 51
#define ACRYPTO_ERR_SSA_INVALID_TOTAL_SHARES          ACRYPTO_ERR_BASE - 52
#define ACRYPTO_ERR_SSA_INVALID_REQUIRED_SHARES       ACRYPTO_ERR_BASE - 53
#define ACRYPTO_ERR_SSA_SHARES_ALREADY_ALLOCATED      ACRYPTO_ERR_BASE - 54
#define ACRYPTO_ERR_SSA_SHARE_ALREADY_LOADED          ACRYPTO_ERR_BASE - 55
#define ACRYPTO_ERR_SSA_INVALID_SHARE_NUMBER          ACRYPTO_ERR_BASE - 56
#define ACRYPTO_ERR_SSA_EMPTY_SHARE_BUFFER            ACRYPTO_ERR_BASE - 57
#define ACRYPTO_ERR_SSA_INVALID_RAND_FUNC             ACRYPTO_ERR_BASE - 58

enum E_keyiv { ACRYPTO_KEY = 1, ACRYPTO_IV = 2 };
enum E_enc_dec { DECRYPT = 0, ENCRYPT = 1};
enum E_certmode { ACRYPTO_CA_PEM = 1, ACRYPTO_CA_DER = 2, ACRYPTO_CA_NET = 3 };
enum E_asymmode { RSA_MODE = 1, DSA_MODE = 2, DH_MODE = 3 };

#define VALID_MODE(x)			((x == ENCRYPT)||(x == DECRYPT))
#define ACRYPTO_CA_VALID_MODE(mode)		(((mode == ACRYPTO_CA_PEM)||(mode == ACRYPTO_CA_DER)||(mode == ACRYPTO_CA_NET)) ? mode : 0)
#define AS_VALID_MODE(mode)		(((mode == RSA_MODE)||(mode == DSA_MODE)||(mode == DH_MODE)) ? mode : 0)
#define PADDING_VALID_MODE(mode)	(((mode == RSA_PKCS1_PADDING)||(mode == RSA_SSLV23_PADDING)||(mode == RSA_NO_PADDING)) ? mode : 0)

#endif
